<template>
  <div>
    <a-select
      show-search
      placeholder="请选择"
      option-filter-prop="children"
      @change="handleChange"
      v-model="selected"
    >
      <a-select-option v-for="courierCompany in courierCompanyList" :key="courierCompany.id" :value="courierCompany.id">
        {{ courierCompany.name }}
      </a-select-option>
    </a-select>
  </div>
</template>

<script>
  import { getCourierCompanyList } from '@/api/system'

  export default {
    name: 'CourierCompanySelection',
    props: {
      value: {
        type: Array,
        default: () => []
      }
    },
    watch: {
      value: {
        handler (value) {
          this.selected = value
        },
        immediate: true
      }
    },
    created () {
      getCourierCompanyList({ per_page: 999 }).then(res => {
        this.courierCompanyList = res.data
      })
    },
    data () {
      return {
        selected: [],
        courierCompanyList: []
      }
    },
    methods: {
      handleChange (value) {
        this.$emit('change', [value])
        this.$emit('input', [value])
      }
    }
  }
</script>

<style scoped>

</style>
